package top.yoahh.system.controller;


import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.yoahh.annotation.AutoLog;
import top.yoahh.system.query.SysMenuQueryInfo;

import top.yoahh.common.Result;
import top.yoahh.system.entity.SysMenu;

import java.util.List;

import org.springframework.web.bind.annotation.RestController;
import top.yoahh.system.service.SysMenuService;

/**
 * <p>
 * 系统资源-菜单 前端控制器
 * </p>
 *
 * @author hjx
 * @since 2022-05-19
 */
@RestController
@Api(tags = "系统资源-菜单")
@RequestMapping("/sysMenu")
public class SysMenuController {
    @Autowired
    private SysMenuService sysMenuService;

    @AutoLog(value = "系统资源-菜单-新增")
    @ApiOperation(value = "新增")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public Result add(@RequestBody SysMenu sysMenu) {
        sysMenuService.save(sysMenu);
        return Result.ok();
    }

    @AutoLog(value = "系统资源-菜单-分页查询")
    @ApiOperation(value = "分页查询")
    @RequestMapping(value = "/queryPage", method = RequestMethod.POST)
    public PageInfo<SysMenu> queryPage(@RequestBody SysMenuQueryInfo queryInfo) {
        return sysMenuService.queryPage(queryInfo);
    }

    @AutoLog(value = "系统资源-菜单-批量删除")
    @ApiOperation(value = "批量删除")
    @RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
    public Result deleteBatch(@RequestBody List<String> ids) {
        return sysMenuService.deleteBatch(ids);
    }

    @AutoLog(value = "系统资源-菜单-按照ID删除")
    @ApiOperation(value = "按照ID删除")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    public Result delete(@PathVariable("id") String id) {
        return sysMenuService.delete(id);
    }

    @AutoLog(value = "系统资源-菜单-修改")
    @ApiOperation(value = "修改")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Result update(@RequestBody SysMenu sysMenu) {
        sysMenuService.updateById(sysMenu);
        return Result.ok();
    }

    @AutoLog(value = "系统资源-菜单-查询菜单树")
    @ApiOperation(value = "查询菜单树")
    @RequestMapping(value = "/queryMenuTree", method = RequestMethod.POST)
    public Result queryMenuTree(@RequestBody SysMenuQueryInfo queryInfo) {
        return sysMenuService.queryMenuTree(queryInfo);
    }
}
